package o;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class cmc {
    private static final cmc ॱ = new cmc();
    private final List<cly> ˊ = new ArrayList();
    private boolean ˋ = false;
    private final Object ˎ = new Object();
    private clv ˏ;

    private cmc() {
        this.ˊ.add(new cmg());
    }

    public static cmc ˊ() {
        return ॱ;
    }

    public void ˊ(Context context, clv o_clv) {
        if (context == null || o_clv == null) {
            throw new NullPointerException("context or param must not be null.");
        } else if (!this.ˋ) {
            this.ˏ = o_clv;
            synchronized (this.ˎ) {
                this.ˊ.clear();
                this.ˊ.addAll(o_clv.ˏ());
                for (cly ˋ : this.ˊ) {
                    ˋ.ˋ(context, o_clv);
                }
            }
            this.ˋ = true;
            ॱ(context);
        }
    }

    boolean ॱ(int i) {
        if (this.ˏ != null) {
            if (i >= this.ˏ.ˋ()) {
                return true;
            }
            return false;
        } else if (i < 4) {
            return false;
        } else {
            return true;
        }
    }

    boolean ˏ() {
        if (this.ˏ != null) {
            return this.ˏ.ॱ();
        }
        return false;
    }

    boolean ॱ() {
        if (this.ˏ != null) {
            return this.ˏ.ˎ();
        }
        return false;
    }

    public void ॱ(String str, int i, String str2, String str3, Throwable th) {
        synchronized (this.ˎ) {
            for (cly ॱ : this.ˊ) {
                ॱ.ॱ(str, i, str2, str3, th);
            }
        }
    }

    private void ॱ(Context context) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault());
        StringBuilder stringBuilder = new StringBuilder("\n");
        stringBuilder.append("==================================================\n");
        stringBuilder.append("== Package: " + context.getPackageName() + "\n");
        stringBuilder.append("== Version: " + ˊ(context) + "\n");
        stringBuilder.append("== Process: " + ˋ(context) + "\n");
        stringBuilder.append("== Time: " + simpleDateFormat.format(Long.valueOf(System.currentTimeMillis())) + "\n");
        stringBuilder.append("==================================================\n");
        String stringBuilder2 = stringBuilder.toString();
        ॱ(stringBuilder2, 4, "", stringBuilder2, null);
    }

    private static String ˊ(Context context) {
        PackageManager packageManager = context.getPackageManager();
        if (packageManager == null) {
            Log.e("LogImpl", "Failed to get instance of PackageManager.");
            return "";
        }
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            if (packageInfo != null) {
                return String.valueOf(packageInfo.versionCode) + " : " + (packageInfo.versionName == null ? "" : packageInfo.versionName);
            }
            Log.e("LogImpl", "Failed to read Package-Info(versionName and versionCode).");
            return "";
        } catch (Throwable e) {
            Log.e("LogImpl", "An error occurred while read Package-Info(versionName and versionCode).", e);
        }
    }

    private static String ˋ(Context context) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
        if (activityManager == null) {
            Log.e("LogImpl", "Failed to get instance of ActivityManager.");
            return "";
        }
        List<RunningAppProcessInfo> runningAppProcesses = activityManager.getRunningAppProcesses();
        if (runningAppProcesses != null) {
            int myPid = Process.myPid();
            for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
                if (runningAppProcessInfo.pid == myPid && !TextUtils.isEmpty(runningAppProcessInfo.processName)) {
                    return String.valueOf(myPid) + " : " + runningAppProcessInfo.processName;
                }
            }
        }
        Log.e("LogImpl", "Failed to get the current process name.");
        return "";
    }
}
